//
//  ViewController.swift
//  YLTextView
//
//  Created by emma on 2023/8/18.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        let remarkView = view.addView(frame: rect(15, 500, kScreenWidth-30, 120), backgroundColor: rgba(246, 247, 247, 1))
        remarkView.cornerBorder(10, 1, rgb(229))
        
        let remarkTextView = YLTextView(frame: rect(15, 12, kScreenWidth-60, 120-24), textColor: rgb(153), font: medium(16), textAlignment: .left, adaptView: view)
        //设置placeholder
        remarkTextView.setupPlaceholderLabel(placeholder: "如果还有其他不适症状、活动行为需要说明，请在此补充", placeholderColor: rgb(213), topMargin: 8)
        //设置文字个数限制
        remarkTextView.setupCountLabel(textColor: rgb(153), font: regular(14), textAlignment: .right, limitWords: 100, height: 19)
        remarkView.addSubview(remarkTextView)
    }
}

extension UIView {
    //MARK: 添加视图
    func addView(frame: CGRect, backgroundColor: UIColor? = nil, isHidden: Bool = false) -> UIView {
        let view = UIView(frame: frame)
        view.backgroundColor = backgroundColor
        view.isHidden = isHidden
        addSubview(view)
        return view
    }
    ///注意这个是会隐藏超出的部分
    func corner(cornerRadius: CGFloat, masksToBounds: Bool) {
        self.layer.masksToBounds = masksToBounds
        self.layer.cornerRadius = cornerRadius
    }
    func corner(_ cornerRadius: CGFloat) {
        self.layer.masksToBounds = true
        self.layer.cornerRadius = cornerRadius
    }
    func cornerBorder(_ cornerRadius: CGFloat, _ borderWidth: CGFloat, _ borderColor: UIColor) {
        self.layer.masksToBounds = true
        self.layer.cornerRadius = cornerRadius
        self.layer.borderColor = borderColor.cgColor
        self.layer.borderWidth = borderWidth
    }
}
